package androidx.fragment.app;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnDismissListener;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import androidx.annotation.RestrictTo.d;
import androidx.annotation.StyleRes;
import o.FragmentTransaction;

public class DialogFragment extends Fragment implements OnCancelListener, OnDismissListener {
    boolean ʼ;
    boolean ʽ;
    int ˊ = 0;
    boolean ˋ = true;
    int ˎ = -1;
    boolean ˏ = true;
    int ॱ = 0;
    boolean ॱॱ;
    @Nullable
    Dialog ᐝ;
    private Handler ﹳ;
    private Runnable ﾞ = new Runnable(this) {
        final /* synthetic */ DialogFragment ˊ;

        {
            this.ˊ = r1;
        }

        public void run() {
            if (this.ˊ.ᐝ != null) {
                this.ˊ.onDismiss(this.ˊ.ᐝ);
            }
        }
    };

    void ˊ(boolean z, boolean z2) {
        if (!this.ʽ) {
            this.ʽ = true;
            this.ʼ = false;
            if (this.ᐝ != null) {
                this.ᐝ.setOnDismissListener(null);
                this.ᐝ.dismiss();
                if (!z2) {
                    if (Looper.myLooper() == this.ﹳ.getLooper()) {
                        onDismiss(this.ᐝ);
                    } else {
                        this.ﹳ.post(this.ﾞ);
                    }
                }
            }
            this.ॱॱ = true;
            if (this.ˎ >= 0) {
                ʿ().ˋ(this.ˎ, 1);
                this.ˎ = -1;
                return;
            }
            FragmentTransaction ˊ = ʿ().ˊ();
            ˊ.ˊ(this);
            if (z) {
                ˊ.ˋ();
            } else {
                ˊ.ˏ();
            }
        }
    }

    @StyleRes
    public int ॱ() {
        return this.ˊ;
    }

    public void ॱ(@NonNull Context context) {
        super.ॱ(context);
        if (!this.ʼ) {
            this.ʽ = false;
        }
    }

    public void ˎ() {
        super.ˎ();
        if (!this.ʼ && !this.ʽ) {
            this.ʽ = true;
        }
    }

    public void ˏ(@Nullable Bundle bundle) {
        super.ˏ(bundle);
        this.ﹳ = new Handler();
        this.ˏ = this.ˍ == 0;
        if (bundle != null) {
            this.ॱ = bundle.getInt("android:style", 0);
            this.ˊ = bundle.getInt("android:theme", 0);
            this.ˋ = bundle.getBoolean("android:cancelable", true);
            this.ˏ = bundle.getBoolean("android:showsDialog", this.ˏ);
            this.ˎ = bundle.getInt("android:backStackId", -1);
        }
    }

    @NonNull
    public LayoutInflater ॱ(@Nullable Bundle bundle) {
        if (!this.ˏ) {
            return super.ॱ(bundle);
        }
        this.ᐝ = ˎ(bundle);
        if (this.ᐝ == null) {
            return (LayoutInflater) this.ˊˊ.ˋॱ().getSystemService("layout_inflater");
        }
        ˏ(this.ᐝ, this.ॱ);
        return (LayoutInflater) this.ᐝ.getContext().getSystemService("layout_inflater");
    }

    @RestrictTo({d.LIBRARY_GROUP_PREFIX})
    public void ˏ(@NonNull Dialog dialog, int i) {
        switch (i) {
            case 1:
            case 2:
                break;
            case 3:
                dialog.getWindow().addFlags(24);
                break;
            default:
                return;
        }
        dialog.requestWindowFeature(1);
    }

    @NonNull
    public Dialog ˎ(@Nullable Bundle bundle) {
        return new Dialog(ˏॱ(), ॱ());
    }

    public void onCancel(@NonNull DialogInterface dialogInterface) {
    }

    public void onDismiss(@NonNull DialogInterface dialogInterface) {
        if (!this.ॱॱ) {
            ˊ(true, true);
        }
    }

    public void ˊ(@Nullable Bundle bundle) {
        super.ˊ(bundle);
        if (this.ˏ) {
            View view = getView();
            if (view != null) {
                if (view.getParent() != null) {
                    throw new IllegalStateException("DialogFragment can not be attached to a container view");
                }
                this.ᐝ.setContentView(view);
            }
            Activity ॱˋ = ॱˋ();
            if (ॱˋ != null) {
                this.ᐝ.setOwnerActivity(ॱˋ);
            }
            this.ᐝ.setCancelable(this.ˋ);
            this.ᐝ.setOnCancelListener(this);
            this.ᐝ.setOnDismissListener(this);
            if (bundle != null) {
                Bundle bundle2 = bundle.getBundle("android:savedDialogState");
                if (bundle2 != null) {
                    this.ᐝ.onRestoreInstanceState(bundle2);
                }
            }
        }
    }

    public void ag_() {
        super.ag_();
        if (this.ᐝ != null) {
            this.ॱॱ = false;
            this.ᐝ.show();
        }
    }

    public void ˋ(@NonNull Bundle bundle) {
        super.ˋ(bundle);
        if (this.ᐝ != null) {
            Bundle onSaveInstanceState = this.ᐝ.onSaveInstanceState();
            if (onSaveInstanceState != null) {
                bundle.putBundle("android:savedDialogState", onSaveInstanceState);
            }
        }
        if (this.ॱ != 0) {
            bundle.putInt("android:style", this.ॱ);
        }
        if (this.ˊ != 0) {
            bundle.putInt("android:theme", this.ˊ);
        }
        if (!this.ˋ) {
            bundle.putBoolean("android:cancelable", this.ˋ);
        }
        if (!this.ˏ) {
            bundle.putBoolean("android:showsDialog", this.ˏ);
        }
        if (this.ˎ != -1) {
            bundle.putInt("android:backStackId", this.ˎ);
        }
    }

    public void ʼ() {
        super.ʼ();
        if (this.ᐝ != null) {
            this.ᐝ.hide();
        }
    }

    public void ᐝ() {
        super.ᐝ();
        if (this.ᐝ != null) {
            this.ॱॱ = true;
            this.ᐝ.setOnDismissListener(null);
            this.ᐝ.dismiss();
            if (!this.ʽ) {
                onDismiss(this.ᐝ);
            }
            this.ᐝ = null;
        }
    }
}
